package bufferedstream;

import java.io.*;

public class Test01 {
    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        //method1();//9.936秒
        //method2();//90.698
        method3();//10.151
        long end = System.currentTimeMillis();
        System.out.println((end - start) / 1000.0 + "秒");
    }
    public static void method1() throws IOException {
        FileInputStream fis = new FileInputStream("C:\\Users\\Zdm\\Desktop\\ubuntu-20.04.6-desktop-amd64.iso");
        FileOutputStream fos = new FileOutputStream("D:\\File\\copy1.iso");
        byte[]bytes = new byte[8192];
        int len;
        while ((len = fis.read(bytes)) != -1){
            fos.write(bytes,0,len);
        }
        fos.close();
        fis.close();
    }
    public static void method2()throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Zdm\\Desktop\\ubuntu-20.04.6-desktop-amd64.iso"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\File\\copy1.iso"));
        int b;
        while ((b = bis.read()) != -1){
            bos.write(b);
        }
        bos.close();
        bis.close();
    }
    public static void method3() throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Zdm\\Desktop\\ubuntu-20.04.6-desktop-amd64.iso"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\File\\copy1.iso"));
        byte[]bytes = new byte[8192];
        int len;
        while ((len = bis.read(bytes)) != -1){
            bos.write(bytes,0,len);
        }
        bos.close();
        bis.close();
    }
}
